﻿Imports System
Imports System.IO
Imports System.Data.OleDb
Imports System.Data
Namespace Arwani
    Partial Class Backend_ManageExhibition
        Inherits System.Web.UI.Page

        Protected Sub lnkAddNewExhibition_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkAddNewExhibition.Click
            Response.Redirect("AddNewExhibition.aspx?exbid=0")
        End Sub
        Public Sub loadData()
            Dim arwCon As New ArwaniController
            Dim strQ As String = "select exh.id,exh.sortorder,exh.title,exh.description,CAST(exh.datefrom as char) as datefrom,CAST(exh.dateto as char) as dateto, exh_cat.catname as category from exhibitions exh, exhibitions_category exh_cat  where exh.catid=exh_cat.catid"
            Dim dtTable As DataTable = arwCon.ExecuteQuery(strQ)
            Me.dgExhibition.DataSource = dtTable
            Me.dgExhibition.DataBind()
        End Sub
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            If (Session("ADMIN_USER") IsNot Nothing) Then
                If Page.IsPostBack = True Then Exit Sub
                Call loadData()
            Else
                Response.Redirect("Default.aspx")
            End If

        End Sub

        Protected Sub dgExhibition_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgExhibition.ItemCommand
            If e.CommandName = "Edit" Then
                Response.Redirect("AddNewExhibition.aspx?exbid=" & CInt(e.CommandArgument))
            ElseIf e.CommandName = "Images" Then
                Response.Redirect("ManageExhibitionGallery.aspx?exbid=" & CInt(e.CommandArgument))
            End If
        End Sub

        Protected Sub dgExhibition_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgExhibition.ItemDataBound
            Try
                Dim lnkDelete As LinkButton = CType(e.Item.FindControl("lnkDelete"), LinkButton)
                lnkDelete.Attributes.Add("onclick", "return confirm('Confirm delete this exhibition?')")

                Dim exhibitionID As Integer = dgExhibition.DataKeys(e.Item.ItemIndex)
                Dim txtSortOrder As TextBox = CType(e.Item.FindControl("txtSortOrder"), TextBox)
                txtSortOrder.Attributes.Add("onblur", "postSortOrder(this.value,'exhibitions', 'id','" & exhibitionID & "')")
            Catch ex As Exception
            End Try
        End Sub

        Protected Sub lnkExhibitionCategory_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkExhibitionCategory.Click
            Response.Redirect("ManageExhibitionCategory.aspx")
        End Sub

        Protected Sub dgExhibition_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgExhibition.DeleteCommand
            ' Dim lnkbtn As LinkButton = TryCast(sender, LinkButton)
            'getting particular row linkbutton
            ' Dim gvrow As GridViewRow = TryCast(lnkbtn.NamingContainer, GridViewRow)
            'getting userid of particular row
            ' Dim gvrow As DataGrid =TryCast(l)



            Dim id As Integer = e.CommandArgument

            'Dim username As String = gvrow.Cells(0).Text

            Dim arwCon As New ArwaniController
            Dim cmd As String = "delete from exhibitions where Id=" & id

            arwCon.ExecuteNonQuery(cmd)

            'If result = 1 Then
            loadData()
            'Displaying alert message after successfully deletion of user

            'End If



        End Sub
    End Class
End Namespace